From 68ab2eaacdd42be91c89e47860a44984e59e8b48 Mon Sep 17 00:00:00 2001 From: "robertlipe@gmail.com" Date: Sat, 8 Dec 2012 08:27:32 +0000 Subject: [PATCH] Make pocketfms reader more robust on a waypoint name with a space in it and make the writer not include a space. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4214 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/pocketfms_wp.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/gpsbabel/pocketfms_wp.c b/gpsbabel/pocketfms_wp.c index 8f53fed63..a43dce3fb 100644 --- a/gpsbabel/pocketfms_wp.c +++ b/gpsbabel/pocketfms_wp.c @@ -68,10 +68,20 @@ data_read(void) wpt = waypt_new(); s = buff; s = csv_lineparse(s, "\\w", "", linecount); + if (!s) { + fatal(MYNAME "Invalid name"); + } wpt->shortname = xstrdup(s); s = csv_lineparse(NULL, "\\w", "", linecount); + if (!s) { + fatal(MYNAME "Invalid latitude %s", wpt->shortname); + } wpt->latitude = wppos_to_dec(s); + s = csv_lineparse(NULL, "\\w", "", linecount); + if (!s) { + fatal(MYNAME "Invalid longitude %s", wpt->shortname); + } wpt->longitude = wppos_to_dec(s); waypt_add(wpt); } @@ -92,7 +102,24 @@ wr_init(const char *fname) static void enigma_waypt_disp(const waypoint *wpt) { - gbfprintf(file_out, "%s %f %f\n", wpt->shortname, wpt->latitude, wpt->longitude); + char *t; + if (wpt->shortname) { + // The output might have a space or control character. + int i, l = strlen(wpt->shortname); + t = xmalloc(l); + char *d = t; + for (i = 0; i < l; i++) { + char s = wpt->shortname[i]; + if(isgraph(s)) { + *d++ = s; + } + } + *d = 0; + } else { + t = xstrdup("NONAME"); + } + gbfprintf(file_out, "%s %f %f\n", t, wpt->latitude, wpt->longitude); + xfree(t); } static void -- 2.30.2